#define _CRT_SECURE_NO_WARNINGS
#ifndef _CREATTASK
#define _CREATTASK

#include <iostream>
#include <string>
#include <sstream>
#include "ros/ros.h"
#include <json11/json11.hpp>

class creatPathTask{
public:
    creatPathTask(const string& name_,const string& type_)
    :name(name_),type(type_)
    {

    }
    Json creatPathJson(){
        Json path_json = Json::object{
            {"name",name},
            {"type",type}
        };
        return path_json;
    }
public:
    string name;
    string type;
};


class creatTask{
public:
    creatTask(const string& task_name_,const string& map_name_,const string& type_)
    :task_name(task_name_),name(task_name_),map_name(map_name_),type(type_)
    {
        brushLevel=66;
        brushLift=66;
        waterSpray=66;
        wiperLift=66;
        vacuum=66;
        shakeLevel=66;

    }
public:
    int brushLevel;
	int brushLift;
	int waterSpray;
	int wiperLift;
	int vacuum;
    int shakeLevel;

    string type;
	string name;

    string task_name;
	string map_name;
};

Json getTaskJson(const string& task_name_,const string& map_name_,const string& type_){
	creatTask c_task(task_name_,map_name_,type_);

	Json motor_level = Json::object{
		{"brushLevel",c_task.brushLevel},
		{"brushLift",c_task.brushLift},
		{"waterSpray",c_task.waterSpray},
		{"wiperLift",c_task.wiperLift},
		{"vacuum",c_task.vacuum},
        {"shakeLevel",c_task.shakeLevel}
	};

	Json use_path_ = Json::object{
		{"type",c_task.type},
		{"name",c_task.name},
		{"motor_level",motor_level}
	};
    Json::array t;
    t.push_back(use_path_);
    Json use_path = t;

	Json taskJson = Json::object{
		{"task_name",c_task.task_name},
		{"map_name",c_task.map_name},
		{"use_path",use_path}
	};
	return taskJson;
}
Json::object handleTaskJsonToApp(Json::object object_){
    Json::object err = Json::object{};
    string map_name = object_["map_name"].string_value();
    string path;
    string path_name;
    Json::array use_path_array = object_["use_path"].array_items();
    Json::array t;
    for(int i = 0;i<use_path_array.size();i++){
        Json motor_level = Json::object{
            {"brushLevel",object_["use_path"][i]["motor_level"]["brushLevel"].int_value()},
            {"brushLift",object_["use_path"][i]["motor_level"]["brushLift"].int_value()},
            {"waterSpray",object_["use_path"][i]["motor_level"]["waterSpray"].int_value()},
            {"wiperLift",object_["use_path"][i]["motor_level"]["wiperLift"].int_value()},
            {"vacuum",object_["use_path"][i]["motor_level"]["vacuum"].int_value()},
            {"shakeLevel",object_["use_path"][i]["motor_level"]["shakeLevel"].int_value()}

        };
        path_name = object_["use_path"][i]["name"].string_value();
        path = "/root/TIC_MAP/" + map_name + "/path/" +path_name +".txt";
		ROS_INFO("path :%s",path.c_str());
		Json path_json = deal_path(path);
        Json use_path_ = Json::object{
            {"type",object_["use_path"][i]["type"].string_value()},
            {"name",object_["use_path"][i]["name"].string_value()},
            {"path_data",path_json},
            {"motor_level",motor_level}
        };
        
        t.push_back(use_path_);
    }
	Json::object taskJson = Json::object{
		{"task_name",object_["task_name"].string_value()},
		{"map_name",object_["map_name"].string_value()},
		{"use_path",t}
	};
	return taskJson;
}
#endif